﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Masters/WithoutPermBasic.Master" CodeBehind="ScanDelivery.aspx.cs" Inherits="PMS.UI.CM.ScanDelivery" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var BarCode = com.get.BarCode;
        var Id;
        $(function () {
            $("#SweepCode").focus();

            //Jquery监听扫码枪回车事件
            $("#SweepCode").keyup(function (event) {
                if (event.keyCode == 13) {
                    var code = $(this).val();
                    code = code.replace(/\n/g, "")
                    $(this).val("");
                    BarCode = code;
                    LoadTableByBarCode(code);
                }
            });

            if (BarCode != null) {
                LoadTableByBarCode(BarCode);
            }
        });

    </script>
    <script type="text/javascript">
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/CM/BottleDeliveryAjax.aspx?method=GetScanDeliveryRecord',
                loadMsg: '数据加载中请稍后……',
                rownumbers: true,
                striped: true,
                singleSelect: true,
                columns: [[
                    { field: 'ck', checkbox: true, width: 30 },
                     { field: 'ProductOrderCode', title: '生产单号', align: "center", width: 100 },
                     { field: 'CustomerName', title: '客户名', align: "center", width: 100 },
                    { field: 'ProductName', title: '产品名称', align: "center", width: 200 },
                    {
                        field: 'TechParams', title: '技术参数', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            //鼠标放在文本处自动显示tooltip
                            return '<span title=' + value + '>' + value + '</span>';

                        }
                    },
                    { field: 'BottleVolume', title: '规格（L）', align: "center", width: 60 },
                    { field: 'OrderCount', title: '产品订货数', align: "center", width: 60 },
                     { field: 'SerialCode', title: '配气流水号', align: "center", width: 100 },
                     {
                         field: 'State', title: '气瓶状态', align: "center", width: 60,
                         formatter: function (value, row, Index) {
                             return com.getArrayText(StaticCombo.BottleState, value);
                         }
                     },
                    { field: 'BottleCode', title: '气瓶编号', align: "center", width: 100 },
                 { field: 'BottleVolume', title: '气瓶容积（L）', align: "center", width: 60 },
                  { field: 'CommissionDate', title: '投产日期', align: "center", width: 100, sortable: true },
                  { field: 'CompletedDate', title: '配气完成日期', align: "center", width: 100, sortable: true },
                  { field: 'AnalyseDate', title: '分析日期', align: "center", width: 100, sortable: true },
                  { field: 'InStorageDate', title: '入库日期', align: "center", width: 100, sortable: true },
                  {
                      field: 'AnalyseRes', title: '分析结果', align: "center", width: 60,
                      formatter: function (value, row, index) {
                          return com.getArrayText(StaticCombo.BottleAnalyseRes, value)
                      }
                  },
                   { field: 'Note', title: '备注', align: "center", width: 60, sortable: true },
                ]],
                onLoadSuccess: function (data) {
                    //
                    //$("#tbList").datagrid("mergeGridColCells", ["ProductionDetailID", "ProductName", "BottleVolume", "OrderCount", "unit", "SinglePrice", "TotalPrice", "Note"]);
                }
            });
        });



        function LoadTableByBarCode(barCode) {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/Logic/CM/BottleDeliveryAjax.aspx?method=AddDeliveryMiddleRecord",
                data: { 'BarCode': barCode },
                success: function (data) {
                    com.message(data.state, data.msg);
                    $("#tbList").datagrid('reload');
                    $("#SweepCode").focus();
                }
            });
        }

        //删除气瓶
        function funcDelBottle() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                console.log(row.ID);
                $.messager.confirm('确认对话框', '您确定删除选中的气瓶吗？', function (r) {
                    if (r) {
                        com.ajax({
                            url: "/Logic/CM/BottleDeliveryAjax.aspx?method=DelMiddleDeliveryRecord",
                            data: { data: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg);
                                $('#tbList').datagrid('reload');
                            }
                        });
                    }
                });
                
            } else {
                com.message("information", "请选中一行");
            }

        }

        //发货
        function funcDelivery() {
            var rows = $('#tbList').datagrid('getRows');
            if (rows.length == 0) {
                return
            }
            var oId = { deliveryInfo: JSON.stringify(rows) };
            for (var j = 0; j < rows.length; j++) {
                if (rows[0].CustomerName != rows[j].CustomerName) {
                    com.message("error", "存在不一样的客户，请验证后再发货");
                    return;
                }
                if (rows[0].ProductOrderCode != rows[j].ProductOrderCode) {
                    com.message("error", "存在不一样的生产订单，请验证后再发货");
                    return;
                }
                if (rows[j].State == '0') {
                    com.message("error", "存在还未配气完成的气瓶，请验证后再发货");
                    return;
                }
                if (rows[j].State == '1') {
                    com.message("error", "存在还未分析完成的气瓶，请验证后再发货");
                    return;
                }
                if (rows[j].State == '2') {
                    com.message("error", "存在还未入库的气瓶，请验证后再发货");
                    return;
                }
                if (rows[j].State == '4') {
                    com.message("error", "存在已经发货的气瓶，请验证后再发货");
                    return;
                }
            }
            com.ajax({
                url: "/Logic/CM/BottleDeliveryAjax.aspx?method=AddDeliveryByScan",
                data: oId,
                success: function (data) {
                    if (data.state == "success") {
                        top.wrapper.addTab("气瓶发货细则", "/UI/CM/BottleDeliveryDetail.aspx?action=add&ID=" + data.deliveryID)
                    }
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
     <div style="height: 100%; overflow: auto">
        <div id="master" class="container_16" style="height: auto;">
            <form id="form1">
                <div class="grid_12 val" style="height: 100px">
                    <textarea id="SweepCode" name="Note" style="width: 900px; height: 80px" placeholder="该区域是扫码区域，扫码之后该气瓶则自动入库"></textarea>
                </div>
                <div class="clear"></div>
                
            </form>
        </div>
    </div>
     <div id="divTable" style="overflow: hidden; height: 500px; width: auto; text-align: center; margin: 0 auto">
        <div id="divToobar" style="background-color: #EFEFEF; overflow: visible;float: left">
            <a href="javascript:void(0)" id="btnDelBottle" class="easyui-linkbutton" onclick="funcDelBottle()"
                data-options="iconCls:'icon-remove',plain:true">删除气瓶</a> &nbsp;&nbsp;
              <a href="javascript:void(0)" id="btnDelivery" class="easyui-linkbutton" onclick="funcDelivery()"
                  data-options="iconCls:'icon-save',plain:true">发货</a> &nbsp;&nbsp;
        </div>
        <table id="tbList" title="发货气瓶信息" style="height: 100%; width: 100%; margin: 0 auto"></table>
    </div>
</asp:Content>

